<template>
    <AntdConfirmModal title="岗位新建" ref="modalRef" :keepSlot="false" @confirm="submitForm">
        <a-form :model="form" name="basic" :label-col="{ span: 6 }">
            <a-form-item label="职级选择" name="jobTypeId" :rules="[{ required: true, message: '请选择岗位分类' }]">
                <a-tree-select disabled v-model:value="form.jobTypeId" tree-data-simple-mode style="width: 100%"
                    :dropdown-style="{ maxHeight: '400px', overflow: 'auto' }" :tree-data="typeOptions" placeholder="请选择岗位分类"
                    :load-data="lazyLoadData" />
            </a-form-item>
            <a-form-item  label="岗位名称" name="jobName" :rules="[{ required: true, message: '请输入岗位名称' }]">
                <a-input v-model:value="form.jobName" />
            </a-form-item>
            <a-form-item  label="岗位编码" name="jobCode" :rules="[{ required: true, message: '请输入岗位编码' }]">
                <a-input disabled v-model:value="form.jobCode" />
            </a-form-item>
            <!-- <a-form-item label="职级系数" name="standard" :rules="[{ required: true, message: '请输入职级系数' }]">
                    <a-input-number v-model:value="form.standard" />
                </a-form-item> -->
            <a-form-item label="岗位状态">
                <a-switch v-model:checked="form.status" :checkedValue="1" :unCheckedValue="0" />
            </a-form-item>
            <a-form-item label="职级排序" name="orderNum">
                <a-input-number v-model:value="form.orderNum" />
            </a-form-item>
            <a-form-item :name="remark" label="备注">
                <a-textarea v-model:value="form.remark" />
            </a-form-item>
        </a-form>
    </AntdConfirmModal>
</template>
<script setup>
import { createOne, queryOne, updateOne } from '@/module/hrm/api/job';
import useJobStore from '@/module/hrm/store/job';
const jobStore = useJobStore();
const typeOptions = computed(() => {
    let arr = $.freeStore(jobStore.types);
    arr.map(ele => {
        ele.label = ele.typeName,
            ele.value = ele.id
    })
    return arr
})
import useApp from '@/hooks';
const { $ } = useApp();
const modalRef = ref(null);
const form = ref({
    jobTypeId: undefined,
    jobName: undefined,
    jobCode: undefined,
    orderNum: 1,
    status: 1,
    remark: undefined
})

$.on('update-job', id => {
    queryOne(id).then(res=>{
        form.value = res;
        modalRef.value.openModal();
    })
    
})
/** 提交按钮 */
function submitForm() {
    updateOne(form.value).then(res => {
        console.log(res)
        $.showToast({
            title: '更新成功',
            icon: 'success'
        })
        $.emit('fresh-job', null);
        modalRef.value.closeModal()
    })
}

</script>